package com.rohoo.news.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.rohoo.framework.dao.DataPackage;
import com.rohoo.news.bo.News;
import com.rohoo.news.dao.NewsDAO;
import com.rohoo.news.dto.NewsDTO;
import com.rohoo.news.service.NewsService;

public class NewsServiceImpl implements NewsService {
	private NewsDAO newsDAO;
	
	public void addNews(News news) throws Exception {
		try {
			newsDAO.addNews(news);
		} catch (Exception e) {
			throw new Exception("NewsServiceImpl addNews Error!", e);
		}
	}
	
	public void updateNews(NewsDTO dto) throws Exception {
		try {
			newsDAO.updateNews(dto);
		} catch (Exception e) {
			throw new Exception("NewsServiceImpl updateNews Error!", e);
		}
	}
	
	public News getNews(Integer news_id) throws Exception {
		try {
			return (News)newsDAO.getNews(news_id);
		} catch (Exception e) {
			throw new Exception("NewsServiceImpl getNews Error!", e);
		}
	}
	
	public List getNewsTitleList(NewsDTO dto) throws Exception {
		try {
			List list = newsDAO.getNewsList(dto);
			ArrayList resultlist = new ArrayList();
			int len = list.size();
			for(int i=0;i<dto.getRowNum()&&i<len;i++){
				resultlist.add(list.get(i));
			}
			for(int i=0;i+len<dto.getRowNum();i++){
				resultlist.add(new Object());
			}
			return resultlist;
		} catch (Exception e) {
			throw new Exception("NewsServiceImpl getNewsTitleList Error!", e);
		}
	}

	public NewsDAO getNewsDAO() {
		return newsDAO;
	}

	public void setNewsDAO(NewsDAO newsDAO) {
		this.newsDAO = newsDAO;
	}

	public DataPackage queryNews(NewsDTO dto) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
}
